import 'package:flutter/material.dart';

class DialogTemplate extends StatefulWidget {
  final void Function()? onCancel;
  final void Function()? onOk;
  final Widget child;
  final double? width;
  final double? height;
  const DialogTemplate(
      {super.key,
      required this.child,
      this.onOk,
      this.onCancel,
      this.width,
      this.height});
  @override
  State<DialogTemplate> createState() => _DialogTemplateState();
}

class _DialogTemplateState extends State<DialogTemplate> {
  @override
  Widget build(BuildContext context) {
    double dlgWidth = 560;
    return Container(
      width: dlgWidth,
      height: widget.height ?? 360,
      padding: const EdgeInsets.all(20),
      child: Column(
        children: [
          widget.child,
          const Spacer(),
          Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              ElevatedButton(
                  onPressed: () {
                    widget.onCancel?.call();
                  },
                  child: const Text("取消")),
              const SizedBox(
                width: 10,
              ),
              ElevatedButton(
                  onPressed: () {
                    widget.onOk?.call();
                  },
                  child: const Text("确定")),
            ],
          )
        ],
      ),
    );
  }
}
